package com.distribution.system.controller;

import com.distribution.common.core.controller.BaseController;
import com.distribution.common.core.domain.AjaxResult;
import com.distribution.common.core.page.TableDataInfo;
import com.distribution.framework.config.ServerConfig;
import com.distribution.system.domain.entity.CmccDaBanner;
import com.distribution.system.domain.req.CmccDaBannerQueryReq;
import com.distribution.system.domain.req.CmccDaBannerUpdateReq;
import com.distribution.system.service.CmccDaBannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: GodLu
 * @create: 2024-08-31 17:52
 * @description: 轮播图控制器
 */
@Slf4j
@RestController
@RequestMapping("/cmccDaBanner")
public class CmccDaBannerController extends BaseController {
    @Value("${swagger.pathMapping}")
    private String pathMapping;
    @Resource
    ServerConfig serverConfig;
    @Resource
    CmccDaBannerService cmccDaBannerService;

    @PostMapping("list")
    public TableDataInfo bannerList(@RequestBody CmccDaBannerQueryReq cmccDaBannerQueryReq){
        startPage();
        List<CmccDaBanner> list = cmccDaBannerService.selectByQueryParam(cmccDaBannerQueryReq);
        return getDataTable(list);
    }

    @PostMapping("getById")
    public AjaxResult getBannerById(@RequestBody Integer id){
        CmccDaBanner cmccDaBanner = cmccDaBannerService.getById(id);
        cmccDaBanner.setImgPath(serverConfig.getUrl() + pathMapping + cmccDaBanner.getImgPath());
        return success(cmccDaBanner);
    }

    @PostMapping("add")
    public AjaxResult add(@RequestBody CmccDaBanner cmccDaBanner){
        cmccDaBannerService.addBanner(cmccDaBanner);
        return success();
    }

    @PostMapping("delById")
    public AjaxResult delById(@RequestBody Integer id){
        cmccDaBannerService.removeById(id);
        return success();
    }

    @PostMapping("updateBanner")
    public AjaxResult updateBanner(@RequestBody CmccDaBannerUpdateReq cmccDaBannerUpdateReq){
        cmccDaBannerService.updateBanner(cmccDaBannerUpdateReq);
        return success();
    }
}
